﻿using System.Globalization;

namespace Eswat
{
	/// <summary>
	/// Instance of a testing result.
	/// </summary>
	public class TestResult
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="TestResult"/> class.
		/// </summary>
		/// <param name="testStatus">The test status.</param>
		public TestResult(TestStatus testStatus)
			: this(testStatus, string.Empty)
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TestResult"/> class.
		/// </summary>
		/// <param name="testStatus">The test status.</param>
		/// <param name="testDescription">The test description.</param>
		public TestResult(
			TestStatus testStatus,
			string testDescription)
			: this(testStatus, testDescription, "")
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="TestResult"/> class.
		/// </summary>
		/// <param name="testStatus">The test status.</param>
		/// <param name="testDescription">The test description.</param>
		/// <param name="resultDescription">The description.</param>
		public TestResult(
			TestStatus testStatus,
			string testDescription,
			string resultDescription)
		{
			this.Status = testStatus;
			this.TestDescription = testDescription;
			this.ResultDescription = resultDescription;
		}

		/// <summary>
		/// Gets the status.
		/// </summary>
		public TestStatus Status { get; private set; }

		/// <summary>
		/// Gets the test description.
		/// </summary>
		public string TestDescription { get; private set; }

		/// <summary>
		/// Gets the result description.
		/// </summary>
		public string ResultDescription { get; private set; }

		/// <summary>
		/// Returns a <see cref="System.String"/> that represents this instance.
		/// </summary>
		/// <returns>
		/// A <see cref="System.String"/> that represents this instance.
		/// </returns>
		public override string ToString()
		{
			var desc = this.TestDescription;

			if (string.IsNullOrEmpty(desc)) desc = "*NO DESCRIPTION*";

			if (string.IsNullOrEmpty(this.ResultDescription))
				return string.Format(CultureInfo.InvariantCulture, "Test \"{0}\" {1}", desc, this.Status);
			else
				return string.Format(CultureInfo.InvariantCulture, "Test \"{0}\" {1}: {2}", desc, this.Status, this.ResultDescription);
		}
	}
}
